/**
 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.bar.carta.model.impl;

import com.bar.carta.model.Tipo;
import com.bar.carta.model.TipoModel;
import com.bar.carta.model.TipoSoap;

import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
import com.liferay.portal.kernel.json.JSON;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.ProxyUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.model.CacheModel;
import com.liferay.portal.model.impl.BaseModelImpl;
import com.liferay.portal.service.ServiceContext;

import com.liferay.portlet.expando.model.ExpandoBridge;
import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;

import java.io.Serializable;

import java.sql.Types;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * The base model implementation for the Tipo service. Represents a row in the &quot;carta_Tipo&quot; database table, with each column mapped to a property of this class.
 *
 * <p>
 * This implementation and its corresponding interface {@link com.bar.carta.model.TipoModel} exist only as a container for the default property accessors generated by ServiceBuilder. Helper methods and all application logic should be put in {@link TipoImpl}.
 * </p>
 *
 * @author pgonzalm
 * @see TipoImpl
 * @see com.bar.carta.model.Tipo
 * @see com.bar.carta.model.TipoModel
 * @generated
 */
@JSON(strict = true)
public class TipoModelImpl extends BaseModelImpl<Tipo> implements TipoModel {
	/*
	 * NOTE FOR DEVELOPERS:
	 *
	 * Never modify or reference this class directly. All methods that expect a tipo model instance should use the {@link com.bar.carta.model.Tipo} interface instead.
	 */
	public static final String TABLE_NAME = "carta_Tipo";
	public static final Object[][] TABLE_COLUMNS = {
			{ "tipoId", Types.BIGINT },
			{ "createDate", Types.TIMESTAMP },
			{ "activo", Types.BOOLEAN }
		};
	public static final String TABLE_SQL_CREATE = "create table carta_Tipo (tipoId LONG not null primary key,createDate DATE null,activo BOOLEAN)";
	public static final String TABLE_SQL_DROP = "drop table carta_Tipo";
	public static final String DATA_SOURCE = "liferayDataSource";
	public static final String SESSION_FACTORY = "liferaySessionFactory";
	public static final String TX_MANAGER = "liferayTransactionManager";
	public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.entity.cache.enabled.com.bar.carta.model.Tipo"),
			true);
	public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.finder.cache.enabled.com.bar.carta.model.Tipo"),
			true);
	public static final boolean COLUMN_BITMASK_ENABLED = false;

	/**
	 * Converts the soap model instance into a normal model instance.
	 *
	 * @param soapModel the soap model instance to convert
	 * @return the normal model instance
	 */
	public static Tipo toModel(TipoSoap soapModel) {
		Tipo model = new TipoImpl();

		model.setTipoId(soapModel.getTipoId());
		model.setCreateDate(soapModel.getCreateDate());
		model.setActivo(soapModel.getActivo());

		return model;
	}

	/**
	 * Converts the soap model instances into normal model instances.
	 *
	 * @param soapModels the soap model instances to convert
	 * @return the normal model instances
	 */
	public static List<Tipo> toModels(TipoSoap[] soapModels) {
		List<Tipo> models = new ArrayList<Tipo>(soapModels.length);

		for (TipoSoap soapModel : soapModels) {
			models.add(toModel(soapModel));
		}

		return models;
	}

	public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.util.service.ServiceProps.get(
				"lock.expiration.time.com.bar.carta.model.Tipo"));

	public TipoModelImpl() {
	}

	public long getPrimaryKey() {
		return _tipoId;
	}

	public void setPrimaryKey(long primaryKey) {
		setTipoId(primaryKey);
	}

	public Serializable getPrimaryKeyObj() {
		return new Long(_tipoId);
	}

	public void setPrimaryKeyObj(Serializable primaryKeyObj) {
		setPrimaryKey(((Long)primaryKeyObj).longValue());
	}

	public Class<?> getModelClass() {
		return Tipo.class;
	}

	public String getModelClassName() {
		return Tipo.class.getName();
	}

	@JSON
	public long getTipoId() {
		return _tipoId;
	}

	public void setTipoId(long tipoId) {
		_tipoId = tipoId;
	}

	@JSON
	public Date getCreateDate() {
		return _createDate;
	}

	public void setCreateDate(Date createDate) {
		_createDate = createDate;
	}

	@JSON
	public boolean getActivo() {
		return _activo;
	}

	public boolean isActivo() {
		return _activo;
	}

	public void setActivo(boolean activo) {
		_activo = activo;
	}

	@Override
	public Tipo toEscapedModel() {
		if (_escapedModelProxy == null) {
			_escapedModelProxy = (Tipo)ProxyUtil.newProxyInstance(_classLoader,
					_escapedModelProxyInterfaces,
					new AutoEscapeBeanHandler(this));
		}

		return _escapedModelProxy;
	}

	@Override
	public ExpandoBridge getExpandoBridge() {
		if (_expandoBridge == null) {
			_expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(0,
					Tipo.class.getName(), getPrimaryKey());
		}

		return _expandoBridge;
	}

	@Override
	public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
		getExpandoBridge().setAttributes(serviceContext);
	}

	@Override
	public Object clone() {
		TipoImpl tipoImpl = new TipoImpl();

		tipoImpl.setTipoId(getTipoId());
		tipoImpl.setCreateDate(getCreateDate());
		tipoImpl.setActivo(getActivo());

		tipoImpl.resetOriginalValues();

		return tipoImpl;
	}

	public int compareTo(Tipo tipo) {
		long primaryKey = tipo.getPrimaryKey();

		if (getPrimaryKey() < primaryKey) {
			return -1;
		}
		else if (getPrimaryKey() > primaryKey) {
			return 1;
		}
		else {
			return 0;
		}
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}

		Tipo tipo = null;

		try {
			tipo = (Tipo)obj;
		}
		catch (ClassCastException cce) {
			return false;
		}

		long primaryKey = tipo.getPrimaryKey();

		if (getPrimaryKey() == primaryKey) {
			return true;
		}
		else {
			return false;
		}
	}

	@Override
	public int hashCode() {
		return (int)getPrimaryKey();
	}

	@Override
	public void resetOriginalValues() {
	}

	@Override
	public CacheModel<Tipo> toCacheModel() {
		TipoCacheModel tipoCacheModel = new TipoCacheModel();

		tipoCacheModel.tipoId = getTipoId();

		Date createDate = getCreateDate();

		if (createDate != null) {
			tipoCacheModel.createDate = createDate.getTime();
		}
		else {
			tipoCacheModel.createDate = Long.MIN_VALUE;
		}

		tipoCacheModel.activo = getActivo();

		return tipoCacheModel;
	}

	@Override
	public String toString() {
		StringBundler sb = new StringBundler(7);

		sb.append("{tipoId=");
		sb.append(getTipoId());
		sb.append(", createDate=");
		sb.append(getCreateDate());
		sb.append(", activo=");
		sb.append(getActivo());
		sb.append("}");

		return sb.toString();
	}

	public String toXmlString() {
		StringBundler sb = new StringBundler(13);

		sb.append("<model><model-name>");
		sb.append("com.bar.carta.model.Tipo");
		sb.append("</model-name>");

		sb.append(
			"<column><column-name>tipoId</column-name><column-value><![CDATA[");
		sb.append(getTipoId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>createDate</column-name><column-value><![CDATA[");
		sb.append(getCreateDate());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>activo</column-name><column-value><![CDATA[");
		sb.append(getActivo());
		sb.append("]]></column-value></column>");

		sb.append("</model>");

		return sb.toString();
	}

	private static ClassLoader _classLoader = Tipo.class.getClassLoader();
	private static Class<?>[] _escapedModelProxyInterfaces = new Class[] {
			Tipo.class
		};
	private long _tipoId;
	private Date _createDate;
	private boolean _activo;
	private transient ExpandoBridge _expandoBridge;
	private Tipo _escapedModelProxy;
}